﻿using Microsoft.AspNetCore.Http;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using static InfrastructureBase.Data.MongoConnection;

namespace InfrastructureBase.Data
{
    public interface IMongoConnection
    {
        /// <summary>
        /// 获取当前数据库
        /// </summary>
        IMongoDatabase Database { get; }

        /// <summary>
        /// 获取数据库连接
        /// </summary>
        MongoClient GetMongoClient { get; }

        /// <summary>
        /// 获取数据库
        /// </summary>
        /// <returns></returns>
        IMongoDatabase GetDataBase(string dataBaseName= default);

        /// <summary>
        /// 获取集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IMongoCollection<T> GetCollections<T>();

        /// <summary>
        /// 新增文件到集合
        /// </summary>
        void AddEntityToCollection<T>(T item, string collectionName = default);

        /// <summary>
        /// 新增文件到集合
        /// </summary>
        Task AddEntityToCollectionAsync<T>(T item,string collectionName= default);

        /// <summary>
        /// 新增文件到集合
        /// </summary>
        void AddEntitiesToCollection<T>(List<T> items,string collectionName= default);

        /// <summary>
        /// 删除实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="collectionName"></param>
        void DeleteEntityToCollection<T>(FilterDefinition<T> item, string collectionName = default);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="filterDefinition"></param>
        /// <param name="item"></param>
        void UpdateEntityToCollection<T>(FilterDefinition<T> filterDefinition, UpdateDefinition<T> item, string collectionName = default);

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <param name="collectionName"></param>
        /// <returns></returns>
        T GetEntity<T>(Expression<Func<T, bool>> func, string collectionName = default);

        /// <summary>
        /// 获取多个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <param name="collectionName"></param>
        /// <returns></returns>
        IEnumerable<T> GetEntities<T>(Expression<Func<T, bool>> func = null, string collectionName = default);

        /// <summary>
        /// 获取多个
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="func"></param>
        /// <param name="collectionName"></param>
        /// <returns></returns>
        IEnumerable<T> GetEntitiesV1<T>(FilterDefinition<T> filterDefinition, string collectionName = null);

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="filterDefinition"></param>
        /// <param name="sortDefinition"></param>
        /// <returns></returns>
        List<T> GetPaingEntitiesData<T>(FilterDefinition<T> filterDefinition, SortDefinition<T> sortDefinition=null,string collectionName = null);

        /// <summary>
        /// 多个文件上传
        /// </summary>
        Task<List<ObjectId>> UploadFileToCollectionAsync(IFormFileCollection formFiles);

        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="item"></param>
        /// <param name="readFileType"></param>
        /// <returns></returns>
        Task<ObjectId> GetObjectIdByFileAsync(IFormFile item, ReadFileType readFileType = ReadFileType.STREAM);

        /// <summary>
        /// objectId获取文件
        /// </summary>
        /// <param name="objectId"></param>
        /// <returns></returns>
        Task<ObjectId> GetFileByObjectIdAsync(ObjectId objectId);
    } 
}
